<?php
session_start();
  require_once "includes/config.php";
  require_once "includes/pagination.php";
  $itemPerPage=10;
  
 $ss = mysql_query("select googleMapKey from tbl_settings where setting_id=1") or die(mysql_error());
 $tbl_settings = mysql_fetch_array($ss);
 if($tbl_settings) $googleMapKey = $tbl_settings['googleMapKey'];  else $googleMapKey='';
?>
<script language="javascript">
   function addtocart(id,amt,sh,q,tax)
   {
	 location.href="addtocart.php?id="+id +"&amt="+amt+"&shipping="+sh+"&qty=1"+"&tax="+tax;
   }
</script>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;oe=utf-8&amp;key=<?php echo $googleMapKey; ?>" type="text/javascript"></script>
<?php
	$sg = $_GET['sg'];
	if($_GET['key']=='search all' || $_GET['key']=='search local' || $_GET['key']=='search online' ||  $_GET['key']=='search for buyer' || $_GET['key']=='search for merchant')
	{
	  $key= '';
	}
	else
	{
	  $key = $_GET['key'];
	}
	$state_1 = $_GET['st'];
	$city_1 = $_GET['cty'];
	$priceFrom = $_GET['pf'];
	$priceTo = $_GET['pt'];
	
	 $search_string= '';
		  $pro_category = '';
		  $pro_subcategory = '';
		  $srch_cond = '';
		  if(isset($_REQUEST['srch1']))
		  {
			  $search_string 	= $_REQUEST['search_string'];
			  $pro_category		= $_REQUEST['pro_category'];
			  $pro_subcategory	= $_REQUEST['pro_subcategory'];
			  
			  if($search_string!='')
				  $srch_cond.=" AND tbl_product.product_name like '%".$search_string."%' ";
			  if($pro_category!='')
				  $srch_cond.=" AND tbl_product.category_id IN (SELECT category_id FROM tbl_category where parent_id=$pro_category) ";
			  if($pro_subcategory!='')
				  $srch_cond.=" AND tbl_product.category_id=$pro_subcategory";
				  
			  
		  }
	
	if(!empty($_GET['sg'])) 
	{	
	
	
	 if(is_numeric($state))
		 $state = getStateName($state);
	 if(is_numeric($city))
		$city = getCityName($city);
		
	 if($city!="" || $state!="")
		  if($city!="" && $state!="") 
			$searchFor=$state." - ".$city;
		  else if($state!="")
		   	$searchFor=$state;
		  else if($city!="")
		   		$searchFor=$city;

		$sqlSelPro="SELECT DISTINCT tbl_items.*,tbl_product.posted_by, tbl_product.product_name, tbl_product.selling_type, tbl_product.shipping, tbl_users.user_id 
					FROM tbl_product, tbl_items, tbl_users 
					WHERE tbl_product.product_id = tbl_items.product_id AND 	 	
					 	  tbl_users.user_id=tbl_items.seller_id $srch_cond ";	
		$searchIncludes="";
		$sqlSelPro .= " AND tbl_product.posted_by IN (select user_id from tbl_users where tbl_users.status='1') ";
		if($city!="" || $state!="") 
		{// City & state search starts
		  $searchIncludes="location";
		  if($city!="" && $state!="") 
			$sqlSelPro .= " AND tbl_users.state LIKE '%$state%' AND tbl_users.city LIKE '%$city%'";
		  else if($state!="")
		   		$sqlSelPro .= " AND tbl_users.state LIKE '%$state%'";
		  else if($city!="")
		   		$sqlSelPro .= " AND tbl_users.city LIKE '%$city%' ";
				
				
				
			if(($priceFrom!="" && is_numeric($priceFrom)) || ($priceTo!=""  && is_numeric($priceTo)))
			 {// Price range including City & state search starts
				if($priceFrom!="" && $priceTo!="" && is_numeric($priceFrom) && is_numeric($priceTo))
					$sqlSelPro .= " AND tbl_items.price BETWEEN $priceFrom AND $priceTo ";
				else if($priceFrom!="" && is_numeric($priceFrom))
			        $sqlSelPro .= " AND tbl_items.price>=$priceFrom ";  
				else if($priceTo!="" && is_numeric($priceTo))
			        $sqlSelPro .= " AND tbl_items.price<=$priceTo ";
		}// Price range including City & state search Ends	
		}// City & state search Ends
		else if(($priceFrom!="" && is_numeric($priceFrom)) || ($priceTo!=""  && is_numeric($priceTo)))
		{// Price range search alone starts
		     $searchIncludes="pricerange";
		     if($priceFrom!="" && $priceTo!="" && is_numeric($priceFrom) && is_numeric($priceTo))
			   $sqlSelPro .= " AND tbl_items.price BETWEEN $priceFrom AND $priceTo ";
			 else if($priceFrom!="" && is_numeric($priceFrom))
			       $sqlSelPro .= " AND tbl_items.price>=$priceFrom ";  
			 else if($priceTo!="" && is_numeric($priceTo))
			        $sqlSelPro .= " AND tbl_items.price<=$priceTo ";
		}// Price range search alone Ends
		if($_GET['sg']=='online')
		{  //show map here
		 if($searchIncludes=="location")
		 {
		   if($key!='')
		     $sqlSelPro.=" AND tbl_product.product_name LIKE '%$key%' AND tbl_product.selling_type='online'"; 
		   else
		     $sqlSelPro.=" AND tbl_product.selling_type='online'";
		 }
		 else if($searchIncludes=="pricerange")
		 {
		   if($key!='')
		     $sqlSelPro.=" AND product_name LIKE '%$key%' AND selling_type='online'"; 
		   else
		     $sqlSelPro.=" AND selling_type='online'";
		  }
		  else
		  {
		    if($key!='')
		     $sqlSelPro.="  AND  tbl_product.product_name LIKE '%$key%' AND tbl_product.selling_type='online'"; 
		   else
		     $sqlSelPro.="  AND  tbl_product.selling_type='online'";
		  }
		  
		  
		 }
		 if($_GET['sg']=='local')
		{
		 if($searchIncludes=="location")
		 {
		   if($key!='')
		     $sqlSelPro.=" AND tbl_product.product_name LIKE '%$key%' AND tbl_product.selling_type='local'"; 
		   else
		     $sqlSelPro.=" AND tbl_product.selling_type='local'";
		 }
		 else if($searchIncludes=="pricerange")
		 {
		   if($key!='')
		     $sqlSelPro.=" AND tbl_product.product_name LIKE '%$key%' AND selling_typetbl_product.='local'"; 
		   else
		     $sqlSelPro.=" AND tbl_product.selling_type='local'";
		  }
		  else
		  {
		    if($key!='')
		     $sqlSelPro.=" AND tbl_product.product_name LIKE '%$key%' AND tbl_product.selling_type='local'"; 
		   else
		     $sqlSelPro.=" AND tbl_product.selling_type='local'";
		  }	
		 }
		 if($_GET['sg']=='all')
		{
		 if($searchIncludes=="location")
		 {
		   if($key!='')
		     $sqlSelPro.=" AND tbl_product.product_name LIKE '%$key%'"; 
		 }
		 else if($searchIncludes=="pricerange")
		 {
		   if($key!='')
		     $sqlSelPro.=" AND tbl_product.product_name LIKE '%$key%'"; 
		  }
		  else
		    if($key!='')
		     $sqlSelPro.="  AND  tbl_product.product_name LIKE '%$key%'"; 
		 }
		 
		 
		 
		  
		  //echo $srch_cond;
		 //echo $sqlSelPro;
		/* else
		{
		$sqlSelPro="SELECT * FROM tbl_product";
		$pagelink="srch&sg";
	} */
		
		/*CODE FOR CALCULATING DISTANCE BETWEEN SIGNED USER AND PRODUCT*/
		//if($_GET['sg']=='online' || $_GET['sg']=='local')
		//{
		  if(!empty($_SESSION['user_id_sess']))
		  {
		   $user_id = $_SESSION['user_id_sess'];
		   $qry = mysql_query("select address_line_1,address_line_2,city,state,country,zip from tbl_users where user_id=$user_id") or die(mysql_error());
		   $cnt_users=mysql_num_rows($qry);
		   if($cnt_users==1)
		   {
		    $users = mysql_fetch_array($qry);
		    $address_line_1 	= $users['address_line_1'];
		    $address_line_2 	= $users['address_line_2'];
		    $address_line_3 	= $users['address_line_3'];
		    $city		= $users['city'];
		    $state		= $users['state'];
		    $country		= $users['country'];
		    $zip		= $users['zip'];
		    
		    $address_of_user	= $address_line_1;
		    if($address_line_2!='')
		     $address_of_user.=",".$address_line_2;
		    if($address_line_3!='')
		     $address_of_user.=",".$address_line_2;
		    if($city!='')
		     $address_of_user.=",".$city;
		    if($state!='')
		     $address_of_user.=",".$state;
		    
		    $cqry = mysql_query("select country_name from tbl_country where country_id=$country") or die(mysql_error());
		    $tbl_country = mysql_fetch_array($cqry);
		    if($tbl_country)
		    {
		     $address_of_user.=",".$tbl_country['country_name'];
		    }
		    
		    if($zip!='')
		    {
		     $address_of_user.=",".$zip;
		    }
		     
		     
		   }
		  }
		//}
		/*CODE FOR CALCULATING DISTANCE BETWEEN SIGNED USER AND PRODUCT*/
  }
	$pLink = "srch&sg=$sg&key=$key&st=$state_1&cty=$city_1&pf=$priceFrom&pt=$priceTo";	
	
	$pos     = strripos($sqlSelPro, "where");
	$curDate = date("Y-m-d G:i:s",time());
	//echo $curDate;
	if($pos == false) {
		$sqlSelPro.="  AND  tbl_items.bargain_duration >= '$curDate'";
	} else {
		//echo "found";
		$sqlSelPro.= " AND tbl_items.bargain_duration >= '$curDate'";
	}
	
	if(!empty($_GET['pricebtw']))
	 {
	      if($_GET['pricebtw']=='1')
	      {
		      $sqlSelPro.=" AND tbl_product.product_price < 10";		
	      }
	      else if($_GET['pricebtw']=='2')
	      {
		      $sqlSelPro.=" AND tbl_product.product_price >= 10 AND tbl_product.product_price <= 50";	
	      }
	      else if($_GET['pricebtw']=='3')
	      {
		      $sqlSelPro.=" AND tbl_product.product_price >= 50 AND tbl_product.product_price <= 100";	
	      }
	      else if($_GET['pricebtw']=='4')
	      {
		      $sqlSelPro.=" AND tbl_product.product_price >= 100 AND tbl_product.product_price <= 500";		
	      }
	      else if($_GET['pricebtw']=='5')
	      {
		      $sqlSelPro.=" AND tbl_product.product_price >500";	
	      }
	 }
	
	if($_GET['sortby']=='online')
	{  //show map here
		     $sqlSelPro.=" AND tbl_product.selling_type='online'";
	}
	elseif($_GET['sortby']=='local')
	{  //show map here
		     $sqlSelPro.=" AND tbl_product.selling_type='local'";
	}
		 
	$sqlSelPro.=" AND tbl_product.quantity>0 ";
	$sqlSelPro.=" group by product_id";
	
	//echo $sqlSelPro;
?>	
<div id='panel' style="width:950px;">
<table>
	<tr>
		<td colspan="2" valign="top">	
		<?php /*?><div style="width: 950px; float: left; vertical-align: top; margin:15px 0px 5px 0px;">
			<a href="#" class="yellow_btn" style="float:right;">Regularly the higher the commission the more you earn per sale<br />
Regularly the lower the commission the more often you sell</a>
			<font class="grey_big" style="float:right; margin:7px 10px 0px 0px;">Pro Tips</font>
		</div><?php */?>
			
		<div style="width: 950px; float: left; margin:10px 0px 5px 0px;">
		
		<div class="mypg_left_out"><a name="top"></a>		
		<!--<a href="#">
		<img src="images/arrow_back.png" style="border:none; margin:0px 5px 0px 0px;" />
		Back to Search Results
		</a>		-->
		</div>
		
		<div class="fullbox_out">	
			<?php /*?><strong class="orangehead">Choose Products to Sell</strong>
			<p style="margin: 5px 0px;" class="grey_txt">
				<i>Sell products for business or people and earn a commission. You choose the item with the best price and commission.</i>
			</p>	<?php */?>
			
			<strong class="orangehead" style="margin:0px 0px 0px 15px;">
			Search Results <?php if(!empty($searchFor)) echo " - ".$searchFor; ?>
			</strong>
	   	</div>
		
	   	</div>
		</td>
	</tr>
</table>

<table width="100%" border="0">

<tr>

<td>
<div style="width: 950px; float: left; vertical-align: top;">


<div class="mypg_left_out">
		<table style="width:100%">
		
		<tr>
        	<td width="214" valign="top">
			<p style="margin:0px 0px 5px 0px;" class="grey2_txt">
				Refine Search
			</p>
			<div class="shourtbox">
			<table width="100%" border="0">
        <?php if($offerSettings)
		{
		?>
		
        <tr>
            <td><table width="212"  border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td></td>
              </tr>
              <tr>
                <td style=" background-image:url(images/LHS_menu_top.jpg); height:10px"></td>
              </tr>
              <tr>
                <td height="30" style=" background-image:url(images/LHS_gradient_bg.jpg); background-repeat:repeat-y;height:100px; vertical-align:top;"><div id="category-title">Offer from <?php echo $sellerName; ?> </div>
                    <br />
                  <div id="category-content"><?php echo $offer; ?></div>
                  </td>
              </tr>
              <tr>
                <td style=" background-image:url(images/LHS_menu_bottom.jpg); height:18px"></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <?php } ?>
          <tr>
            <td>
	  <form id="formShopSearch" name="formShopSearch" method="post" action="">
	    <table cellspacing="0" cellpadding="0" border="0" width="212">
	    <tbody>
		    <tr>
			    <td style="vertical-align: top;">
				    <div id="category-title">Search Within Store</div>
				    <br>
				    <div class="fulldiv">
					    <center>
					    
						    <input type="text" style="width: 120px; float: left;" class="inputbg" id="search_string" name="search_string" value="<?php echo $search_string;?>" />
						    <input type="submit" style="height: 30px; margin: 0px 0px 0px 10px;" class="yellow_btn" value="Search" name="search" onclick="javascript:$('#srch').val('1');" />
					    
					    </center>
				    </div>
			    </td>
		    </tr>

		    <tr>
			    <td style="vertical-align: top;"><br>
				    <div id="category-title">Category</div>
				    <br>

				    
				    
				    <select onchange="getsubsearch(this.value);" class="inputbg" id="pro_category" name="pro_category" style="width:200px;">
					    <?php echo get_category_all(1); ?>
				    </select>
				    
				    <script>$('#pro_category').val(<?php echo $pro_category;?>);</script>

			    </td>
		    </tr>

		    <tr>
			    <td style="vertical-align: top;"><br>
				    <div id="category-title">Sub-Category</div>
				    <br>

				    
				    <select onchange="javascript:var x=document.getElementById('formShopSearch'); x.submit();" class="inputbg" id="pro_subcategory" name="pro_subcategory" style="width:200px;">
					    
					    <?php
					    if($pro_category!='') echo get_category_all($pro_category); else echo '<option selected="selected" value="">Select Sub-Category..</option>'; 
					    ?>
				    </select>
				    <script>$('#pro_subcategory').val(<?php echo $pro_subcategory;?>);</script>
				    <br> <br>

			    </td>
		    </tr>
		    
		    <tr>
			    <td style="vertical-align: top;">
				    <div id="category-title">By Price</div>
				    <p><a href="index.php?addProduct<?php echo $pagelink; ?>&pricebtw=1">under - $10</a></p>  
				    <p><a href="index.php?addProduct<?php echo $pagelink; ?>&pricebtw=2">$10 - $50</a></p>  
				    <p><a href="index.php?addProduct<?php echo $pagelink; ?>&pricebtw=3">$50 - $100</a></p>  
				    <p><a href="index.php?addProduct<?php echo $pagelink; ?>&pricebtw=4">$100 - $500</a></p> 
				    <p><a href="index.php?addProduct<?php echo $pagelink; ?>&pricebtw=5">$500 +</a></p>           
				     </td>
		    </tr>

	    </tbody>
	    </table>
	    <input type="hidden" name="srch1" id="srch1" />
	    </form>
	    </td>
          </tr>
        </table>
			</div>
			</td>
		</tr>
		
		<?php /*?><tr>
			<td>
				<div class="text_box2" style="text-align:center;">
				The more products you pick up the more sales you will have
				</div>
			</td>
		</tr><?php */?>
		
		</table>
</div>

<div class="fullbox_out">
<table style="width:100%">
  <tr>
    <td>
	<div id='panel' style="border:none; width:710px; margin:-16px 0px 0px 5px;">
	

	<div class="fulldiv" style="margin: 10px 0px 0px;">
		 <?php
		                
				  $sprice="hps";
				   $stitle="Lowest Price and Shipping";
				   $cls1="";
				   $cls2="";
				   $cls3="";
				   if(!empty($_REQUEST['sortby'])) {
					if($_REQUEST['sortby']=='lps') {
						$sqlSelPro .= " order by tbl_product.product_price ASC, tbl_product.shipping ASC";
						$sprice="hps";
						$stitle="Highest Price and Shipping";
						
						
					}
					else if($_REQUEST['sortby']=='hps') {
						$sqlSelPro .= " order by tbl_product.product_price DESC, tbl_product.shipping DESC";		
					        $sprice="lps";
						 $stitle="Lowest Price and Shipping";
					}
					else if($_GET['sortby']=='bm') {
						$sqlSelPro .= " order by field(tbl_product.product_name, '$key') DESC";
						$cls1="select";
						
					}
					else if($_GET['sortby']=='gen') {
						$sqlSelPro .= " order by tbl_product.product_id ASC";		
					}
					else if($_GET['sortby']=='local') {
						$sqlSelPro .= " order by field(tbl_product.selling_type,'local') desc";
						$cls2="select";
					}
					else if($_GET['sortby']=='online') {
						$sqlSelPro .= " order by field(tbl_product.selling_type, 'online') desc";
						$cls3="select";
					}
					else if($_GET['sortby']=='price') {
						$sqlSelPro .= " order by tbl_product.product_price ASC";		
					}
				   }		
				   else 
				   {
				    $sqlSelPro .= " order by field(tbl_product.product_name, '$key') DESC";
				    $cls1="select";
				   }
				   
				   
						
				   //echo $sqlSelPro;
				   $rstSelPro=mysql_query(getPagingQuery($sqlSelPro,$itemPerPage));			  
				   $num=mysql_num_rows($rstSelPro);				   
				   if($num==0)
					{
					?><div class="fulldiv">
						<div class="fullbox_top"></div>
						<div class="fullbox_repeat">
						<?php	echo "&nbsp;&nbsp;No Products Found...";?>
						</div>
							<div class="fullbox_bot"></div>
						</div>
					<?					 
					}
				   else { ?>
				   		
					<table align="center" width="100%" border="0">
						<tr>
						<td>
						<div class="fulldiv" style="margin:0px 0px -5px 0px;">
						<table>
						<tr>
							<td width="15%" style="padding:0px 0px 0px 5px;">Sort Options:</td>
							<td width="15%"><a href="index.php?<?php echo $pLink; ?>&sortby=bm" class="<?php echo $cls1?>">Best Match</a></td>
							<?php /*?><td width="27%"><a href="index.php?<?php echo $pLink; ?>&sortby=lps">Lowest Price and Shipping</a></td>
							<td width="29%"><a href="index.php?<?php echo $pLink; ?>&sortby=hps">Highest Price and Shipping</a></td><?php */?>
							<td width="15%"><a href="index.php?<?php echo $pLink; ?>&sortby=online" class="<?php echo $cls3?>">Online Only</a></td>
							<td width="15%"><a href="index.php?<?php echo $pLink;?>&sortby=local" class="<?php echo $cls2?>">Local Only</a></td>
							</tr></table>
				</div></td>
							<td width="30%">
							<form action="" method="post" name="frm_sort">
						<div class="greytab_out" style="margin:0px 10px -12px 5px;">
							
<!--							<div class="yellow_btn" style="cursor:pointer; padding:10px 5px 0px 5px; height:25px;" title="<?php echo $stitle?>" onclick="window.location='index.php?<?php echo $pLink;?>&sortby=<?php echo $sprice?>'">Sort price</div>
-->		
			<select name="sortby" onchange="document.frm_sort.submit();">
			<option value="">Sort Price</option>
			<option value="lps" <?php if($_REQUEST['sortby']==lps) { echo 'selected'; }?>>Lowest To Highest</option>
			<option value="hps" <?php if($_REQUEST['sortby']==hps) { echo 'selected'; }?>>highest To Lowest</option>
			</select>					
						</div></form>
					</td>
						</tr>
					</table>
	</div>
	<?php	
						
	      while($rowSelPro=mysql_fetch_array($rstSelPro))
	      {							   
		$productId=$rowSelPro['product_id'];
		$posted_by=$rowSelPro['posted_by'];
		$itemId=$rowSelPro['item_id'];
		//$productName=wordFormater($rowSelPro['product_name'],46);
		$productName=wordFormater($rowSelPro['product_name'],20);
		$productTitle = $rowSelPro['product_name'];					   
		$productPrice=$rowSelPro['price'];
		$postedDate=$rowSelPro['posted_date'];
		$bargainDate = $rowSelPro['bargain_duration'];
		$timeLeft = getRemainingTime($bargainDate);
		$shipping = $rowSelPro['shipping'];
		if($shipping!="Free") {
		     $shipping = "$".number_format($shipping,2);
		}
		
		$localpick=$rowSelPro['localPickup'];
		
		if($localpick==0)
		 $lpickup="Not available";
		else
		 $lpickup="Available";
		
		$sellType = $rowSelPro['selling_type'];
		$timeLeft = getRemainingTime($bargainDate);
		$pimage = getProductImage($productId,'p');
		if($pimage['thumb']!="") {
			     $productThumb = $pimage['thumb'];
		} else {
			     $productThumb="images/no_image.gif";	
		}
		
		$sqlList="SELECT * FROM tbl_items WHERE product_id='$productId'";
			$rstList=mysql_query($sqlList);
			$rowList=mysql_num_rows($rstList);
			if($rowList>1)
			{
			      $sqlRange="SELECT MIN(price) as min_price FROM tbl_items WHERE product_id='$productId'";
			     $rstRange=mysql_query($sqlRange);
			     $rowRange=mysql_fetch_array($rstRange);
			     $minp=$rowRange['min_price'];
			     $sqlRange="SELECT MAX(price) as max_price FROM tbl_items WHERE product_id='$productId'";
			     $rstRange=mysql_query($sqlRange);
			     $rowRange=mysql_fetch_array($rstRange);
			     $maxp=$rowRange['max_price'];
			}
			$ownername=getUser($posted_by);
			$qry = mysql_query("select address_line_1,address_line_2,city,state,country,zip,user_type from tbl_users where user_id=$posted_by") or die(mysql_error());
			$cnt_users=mysql_num_rows($qry);
			if($cnt_users==1)
			{
			 $users = mysql_fetch_array($qry);
			 $address_line_1 	= $users['address_line_1'];
			 $address_line_2 	= $users['address_line_2'];
			 $address_line_3 	= $users['address_line_3'];
			 $city			= $users['city'];
			 $state			= $users['state'];
			 $country		= $users['country'];
			 $zip		= $users['zip'];
			 
			 $address_of_seller	= $address_line_1;
			 if($address_line_2!='')
			  $address_of_seller.=",".$address_line_2;
			 if($address_line_3!='')
			  $address_of_seller.=",".$address_line_2;
			 if($city!='')
			  $address_of_seller.=",".$city;
			 if($state!='')
			  $address_of_seller.=",".$state;
			 
			 $cqry = mysql_query("select country_name from tbl_country where country_id=$country") or die(mysql_error());
			 $tbl_country = mysql_fetch_array($cqry);
			 if($tbl_country)
			 {
			  $address_of_seller.=",".$tbl_country['country_name'];
			 }
			 
			 if($zip!='')
			 {
			  $address_of_seller.=",".$zip;
			 }
			 
			 $mtype=$users['user_type'];
			}

	 ?>  
			<div class="fulldiv">
			
				<div class="fullbox_top"></div>
				
				<div class="fullbox_repeat">
					<div class="sellpro_table">
						<div class="sellpro_row_img">
							<img src="<?php echo $productThumb; ?>">
						</div>
						
					<div class="sellpro2_out">
						<div class="fulldiv">
						<div class="sellpro_row-2" style=" width:255px;">
							<p class="sellpro_head" style="margin:5px 0px 5px 0px;">
							<a href='index.php?products=<?php echo $itemId; ?>' title='<?php echo $productTitle; ?>' class="sellpro_head"> <?php echo $productName; ?> </a>
							</p>
							<p class="pro_ptag">product owner - <?php echo $ownername?></p><br>							
						</div>
						
						<div class="sellpro_row3" style="text-align:center;">
						     <?php if($mtype==3) {?>
							    <img src="images/m.png" alt="Verified Merchant" title="Verified Merchant" />
							   <?php } ?>
							    <input type="hidden" name="address_of_seller" value="<?php echo $address_of_seller;?>" id="address_of_seller<?php echo $productId;?>" />
							     <script>
								   var geocoder, location1, location2, gDir;
								  
								   geocoder = new GClientGeocoder();
								   gDir = new GDirections();
								  </script>
							     <input type="hidden" name="lat<?php echo $productId;?>" value="" id="lat<?php echo $productId;?>" />
								<input type="hidden" name="lon<?php echo $productId;?>" value="" id="lon<?php echo $productId;?>" />
								
							     <?php
							     
							       if(!empty($_SESSION['user_id_sess']))
							       {
								 
								?>
								
								<input type="hidden" name="address_of_user" value="<?php echo $address_of_user;?>" id="address_of_user" />
								 
								<script>
									    //alert('t');
									    GEvent.addListener(gDir, "load", function() {
										    var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
										    var drivingDistanceKilometers = gDir.getDistance().meters / 1000;
										    //document.getElementById('results').innerHTML = '<strong>Address 1: </strong>' + location1.address + ' (' + location1.lat + ':' + location1.lon + ')<br /><strong>Address 2: </strong>' + location2.address + ' (' + location2.lat + ':' + location2.lon + ')<br /><strong>Driving Distance: </strong>' + drivingDistanceMiles + ' miles (or ' + drivingDistanceKilometers + ' kilometers)';
										    var result = drivingDistanceMiles.toFixed(2);
										    
										    $('#distance').html('miles away - <span style="color:#000000;cursor:pointer;">'+result+' miles</span><br />');
									    });
								  </script>
								<?
								 }
							       ?>
								  <script>
								  
								  var address_of_seller = $('#address_of_seller<?php echo $productId;?>').val();
								  geocoder.getLocations(address_of_seller, function (response) {
									  if (!response || response.Status.code != 200)
									  {
										  //alert("Sorry, we were unable to geocode the first address");
									  }
									  else
									  {
										  
										  
										  location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
										  
										  $('#lat<?php echo $productId;?>').val(response.Placemark[0].Point.coordinates[1]);
										  $('#lon<?php echo $productId;?>').val(response.Placemark[0].Point.coordinates[0]);
										  <?php
										 if(!empty($_SESSION['user_id_sess']))
										 {
							         		  ?>
										  
										  var address_of_user = $('#address_of_user').val();
										  geocoder.getLocations(address_of_user, function (response) {
											  if (!response || response.Status.code != 200)
											  {
												  //alert("Sorry, we were unable to geocode the second address");
											  }
											  else
											  { 
												  location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
												  gDir.load('from: ' + location1.address + ' to: ' + location2.address);
											  }
										  
											  
										  });
										  <?php } ?>
									  }
								   });
								 								  
								 </script> 
							
						</div>
						
						<div class="sellpro_row2" style="text-align:right; font-size:12px; width:180px;">
							<p class="redtxt pro_ptag" style="margin:5px 0px 5px 0px; font-size:12px;">
								$<?php echo number_format($productPrice,2); ?> </font>
							</p>
							<p style="margin:5px 0px 5px 0px;" class="pro_ptag">Shipping:<i><?php echo $shipping; ?></i></p>							
						</div>
						</div>
						
						
						<div class="fulldiv" style="margin:50px 0px 0px 0px;">
						
						<div class="sellpro_row-2" style="width:195px; margin:5px 0px 0px 0px;">
							<p class="pro_ptag" >local pick up - <font style="color:#000000;"><?php echo $lpickup?></font></p>
						</div>
							
						<div class="sellpro_row3" style="text-align:center; width:215px; margin:5px 0px 0px 0px;">
							<?php if($lpickup=='Available') { ?>
						       <div class="fulldiv" align="center" style="margin-top:-27px;"><img src="images/pushpin.png" /></div>
						       <span id="distance" class="grey_txt"></span>&nbsp;
						        (<a class="bluelink" href="javascript:void(0)" onclick="show_map(<?php echo $productId;?>)">map it</a>)<?php } ?>
						</div>
						
						<div class="sellpro_row2" style="text-align:right; font-size:12px; width:135px; margin:0px;">
							<p class="pro_ptag">
							<a href="javascript:void(0);" style="font-size:13px; font-weight:bold;" onclick="return addtocart('<?php echo $itemId;?>','<?php echo $productPrice;?>','<?php echo $shipping;?>',1,'<?php echo $sales_tax;?>');">ADD TO CART <img src="images/cartnew.png" border="0" style="margin:0px 0px -7px 0px;" /></a>
							</p>						
						</div>
						
						</div>
					</div>
					
					</div>
				</div>
				
				<div class="fullbox_bot"></div>
							
			</div>
			

			
						 
		

	    <?php } }?>
	<table width="100%" cellpadding="0" cellspacing="0">
  		<tr>
    		<td><div class="fulldiv" align="center"><?php
				   $link=$pLink;
				   echo $disp=getPagingLink($sqlSelPro,$itemPerPage,$link);							   
			 ?>
		    <a href="#top" style="margin:0px 0px 0px 0px;">back to top</a>	 
		   </div>
		   
			</td>
  		</tr>
	
	</table>
	</div>
	
	</td>
  </tr>
  
</table>
			
			
</div>

</div>

</td>
</tr>  
</table>
</div>

<script>
function show_map(pid,address)
{
  // var pos = $('#more_info_link').position();
  var ntop = ( $(window).height() - $('#map_box').height() ) / 2+$(window).scrollTop();
  var nleft = ( $(window).width() - $('#map_box').width() ) / 2+$(window).scrollLeft();
  
  $('#map_box').css({'left': nleft, 'top':ntop});
  $('#map_box').show();
  var lat = $('#lat'+pid).val();
  var lon = $('#lon'+pid).val();
  //alert(lat+' '+lon);
  initialize(lat,lon);
 
  
}



function initialize(lat,lon) {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(lat, lon), 13);
    var latlng = new GLatLng(lat,lon);
    map.addOverlay(new GMarker(latlng));
    
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
  }
}

function getsubsearch(category_id)
{
	var url = "<?php echo $base_url;?>ajax_category_option.php";
	$.post(url,
	{ 'category_id':category_id},
	function(data)
	{
		$('#pro_subcategory').html(data);
	},
	'html');
	
	var x=document.getElementById("formShopSearch");
	x.submit();
}

</script>
<div id="map_box" style="position:absolute; width:650px; height:470px; background:#000000; display:none;" align="center">
 <span style="float:right; color:#fff; padding:10px; font-weight:bold; cursor:pointer;" onclick="$('#map_box').hide();">x</span><br />
 <div id="map_canvas" style="width: 600px; height: 400px"></div>
</div>